package com.oneraku.service;

import com.baomidou.mybatisplus.core.toolkit.Sequence;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.oneraku.service.domain.AgentSeckill;
import com.oneraku.service.domain.UserInfo;
import com.oneraku.service.domain.WorkOrder;
import com.oneraku.service.filter.LogFilter;
import com.oneraku.service.service.IAgentSeckillService;
import com.oneraku.service.service.IAgentStepInfoService;
import com.oneraku.service.service.IUserInfoService;
import com.oneraku.service.service.IWorkOrderService;
import com.oneraku.service.utils.Bcrypt;
import com.oneraku.service.utils.StepEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

import java.util.List;
import java.util.Random;

@SpringBootApplication
@Slf4j
public class Application implements CommandLineRunner {
	@Autowired
	private IUserInfoService userInfoService;
	@Autowired
	private IAgentStepInfoService stepInfoService;
	@Autowired
	private IAgentSeckillService seckillService;

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args).registerShutdownHook();
	}
	@Override
	public void run(String... args) throws Exception {
		log.info("项目启动成功！");
//		List<UserInfo> userInfoList = userInfoService.list(Wrappers.<UserInfo>lambdaQuery().eq(UserInfo::getAvatar,""));
//		userInfoList.stream().forEach(item->{
//			userInfoService.update(Wrappers.<UserInfo>lambdaUpdate()
//					.set(UserInfo::getAvatar,String.format("https://oneraku-resource.oss-cn-shanghai.aliyuncs.com/avatar/%s.jpg",new Random().nextInt(9)))
//					.eq(UserInfo::getId,item.getId()));
//		});

//		List<AgentSeckill> seckills = seckillService.list();
//		seckills.stream().forEach(item -> {
//			if(item.getType().intValue() == 0 ){
//				stepInfoService.saveBatch(StepEnum.BuyStepEnum.getStepList(item.getId()));
//			} else {
//				stepInfoService.saveBatch(StepEnum.SkillStepEnum.getStepList(item.getId()));
//			}
//		});



	}
	@Bean
	public FilterRegistrationBean devFilterRegistration() {
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(new LogFilter());//添加过滤器
		registration.addUrlPatterns("/*");//设置过滤路径，/*所有路径
		registration.setName("auth");//设置优先级
		registration.setOrder(1);//设置优先级
		return registration;
	}
	@Bean
	public Sequence getSequence(){
		return new Sequence(30L,30L);
	}
}
